﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Utils.MVP;
using RMS.Web.Shell.View;
using RMS.Web.Shell.Presenter;
using System.Data;
using RMS.DataAccess.Entities;

namespace RMS
{
    public partial class SearchInImagesView : Page<SearchInImagesPresenter>, ISearchInImagesView
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnAddImage_Click(object sender, EventArgs e)
        {
            if (ImgFileUpload.HasFile)
            {
                string imagePath = Server.MapPath(Constants.TempFolderPath + Guid.NewGuid() + ImgFileUpload.FileName);
                ImgFileUpload.SaveAs(imagePath);
                var result = this.Presenter.SearchIninImgs(imagePath, System.IO.Path.GetExtension(imagePath));
                gvImges.DataSource = result.Rows;
                gvImges.Visible = true;
                gvImges.DataBind();
            }
        }

        protected void gvImges_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex > -1)
            {
                RadiologyImage row = (RadiologyImage)e.Row.DataItem;
                HyperLink hpl = (HyperLink)e.Row.FindControl("hplImage");
                hpl.NavigateUrl = row.ImagePath.ToVirtualPath() + ".jpg";
            }
        }
    }
}